#include "widget.h"
#include <QApplication>
#include <QTableWidget>
#include <QDebug>
#include <QMessageBox>
#include <QTextCodec>
#include <QTime>
#include "barcode_scan.h"
#include "parcel.h"
#include "parcel_dao.h"

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
    QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));

    Widget widget;
    BarcodeScan scanner;
    ParcelDao parcelDao;


    QObject::connect(&scanner, SIGNAL(barcodeScanned(const QString*)),
                     &widget, SLOT(onBarcodeScanned(const QString*)));
    QObject::connect(&widget, SIGNAL(quitThread()), &scanner, SLOT(quitThread()));

    if(!parcelDao.init()) {
        widget.updateStatus("数据库读取失败", false);
    } else {
        if (scanner.init()) {
            scanner.start();
            widget.updateStatus("正常", true);
        } else {
            widget.updateStatus(scanner.getErrorMsg(), false);
        }
    }

    widget.setWindowState(Qt::WindowFullScreen);
    //widget.showFullScreen();
    widget.show();

    return app.exec();
}
